package ar.camera.renderer.extend;

import java.util.List;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.content.Context;
import android.opengl.GLU;
import ar.camera.globject.MiniMap;
import ar.camera.pojo.GLPoint;
import ar.camera.pojo.GeoLocation;
import ar.camera.renderer.base.BaseRenderer;

public class MiniMapRenderer extends BaseRenderer {

	private MiniMap mMiniCompass;
	private boolean isNeedToLoadTexture;

	@Override
	public void setmListOfGeoLocations(List<GeoLocation> mListOfGeoLocations) {
		super.setmListOfGeoLocations(mListOfGeoLocations);

		this.mMiniCompass.setmListOfGLLocations(this.mListOfGeoLocations,
				this.mMyCurrentGeoLocation);
	}

	public MiniMapRenderer(Context context, GLPoint eye, GLPoint cam) {
		super(context, eye, cam);
		this.mMiniCompass = new MiniMap();
		this.isNeedToLoadTexture = true;
	}

	@Override
	public void onDrawFrame(GL10 gl) {
		super.onDrawFrame(gl);		

		// Drawing
		GLU.gluLookAt(gl, 0f, 0f, 1f, 0f, 0f, -1f, 0f, 1f, 0f);

		gl.glMatrixMode(GL10.GL_PROJECTION);
		gl.glLoadIdentity();
		gl.glFrustumf(-ratio, ratio, -1f, 1f, 0.5f, 100f);

		if (mMiniCompass.isLoadedTexture() == false || isNeedToLoadTexture) {
			mMiniCompass.loadGLTexture(gl, mContext, eye, cam);
			isNeedToLoadTexture = false;
		}
		mMiniCompass.draw(gl);
	}

	@Override
	public void onSurfaceChanged(GL10 gl, int width, int height) {
		super.onSurfaceChanged(gl, width, height);
	}

	@Override
	public void onSurfaceCreated(GL10 gl, EGLConfig config) {
		super.onSurfaceCreated(gl, config);
	}

	@Override
	public void updateVertices(float azimut, GLPoint eye, GLPoint cam) {
		mMiniCompass.updateVertices(azimut);
		if (this.eye.x != eye.x || this.eye.z != eye.z) {
			isNeedToLoadTexture = true;
			this.eye = eye;
		}
	}
}